let arr = [];
for (let i = 0; i < 10; i++) {
    arr.push(Math.floor(Math.random() * 1000));
}


function Node(val) {
    this.value = val;
    this.left = null;
    this.right = null;
}

function createSerchTree(root, val) {
    if (root == null) return null;
    if (root.value == val) return null;
    if (root.value < val) {
        if (root.right == null) {
            root.right = new Node(val);
        } else {
            createSerchTree(root.right, val)
        }
    } else {
        if (root.left == null) {
            root.left = new Node(val);
        } else {
            createSerchTree(root.left, val)
        }
    }
}

function beginFn() {
    let root = new Node(arr[0]);
    for (let i = 1; i < arr.length; i++) {
        createSerchTree(root, arr[i])
    }
    return root;
}
console.log(arr,beginFn());